//
//  SEGUserManagerCell.m
//  SEGUhomePropertyBaseService
//
//  Created by 揭婧雯 on 2018/8/28.
//  Copyright © 2018年 刘山. All rights reserved.
//

#import "SEGUserManagerCell.h"
#import "CommomHeader.h"
@interface SEGUserManagerCell ()
/**
 头像
 */
@property (nonatomic, strong)UIImageView *iconView;
/**
 描述标签
 */
@property (nonatomic, strong)UILabel *nameLabel;
/**
 用户类型
 */
@property (nonatomic, strong)UILabel *typeLabel;
/**
 手机号
 */
@property (nonatomic, strong)UILabel *phoneLabel;

@end

@implementation SEGUserManagerCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    self.backgroundColor = kColor_W;
    
    UIImageView *picView = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:SEGPicName(@"headimg60")]];
    picView.layer.masksToBounds = YES;

    [self.contentView addSubview:picView];
    [picView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.left.equalTo(self.contentView).offset(15);
        make.width.height.mas_equalTo(29);
    }];
    
    [picView seg_configWithRadius:3.f];
    
    self.iconView = picView;
    
    self.nameLabel = [[UILabel alloc] init];
    self.nameLabel.font = kFont_13;
    self.nameLabel.textColor = kColor_1;
    self.nameLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(picView.mas_right).mas_offset(15);
        make.top.equalTo(self.contentView).offset(14);
    }];
    
    UILabel *descLabel = [[UILabel alloc] init];
    descLabel.font = kFont_11;
    descLabel.textColor = kColor_3;
    descLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:descLabel];
    [descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(picView.mas_right).mas_offset(15);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(8);
    }];
    self.typeLabel = descLabel;
    
    UILabel *phoneLabel = [[UILabel alloc] init];
    phoneLabel.font = kFont_11;
    phoneLabel.textColor = kColor_3;
    phoneLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:phoneLabel];
    [phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.typeLabel.mas_right).mas_offset(10);
        make.top.equalTo(self.typeLabel);
    }];
    self.phoneLabel = phoneLabel;
    
    UIButton *deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
    UIImage *image = [UIImage imageWithContentsOfFile:SEGPicName(@"btn_house_del")];
    [deleteButton setImage:image forState:UIControlStateNormal];
    [self.contentView addSubview:deleteButton];
    [deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView);
        make.centerY.equalTo(self.contentView);
        make.width.mas_equalTo(image.size.width + 30);
        make.height.mas_equalTo(image.size.height + 30);
    }];
//    deleteButton.backgroundColor = kColor_T;
    
    self.deleteButton = deleteButton;
    self.deleteButton.hidden = YES;
}

- (void)setUpUserManagerCellWithModel:(SEGUserInfoModel *)model
{
    NSString *urlString = [NSString stringWithFormat:@"%@%@", kClientImageRootURL, model.userIco];
    [self.iconView setImageWithURL:[NSURL URLWithString:urlString] placeholderImage:[UIImage imageWithContentsOfFile:SEGPicName(@"headimg60")]];
    
    self.nameLabel.text = model.nickName;
    self.typeLabel.text = model.userTypeString;
    if (model.tel && model.tel.length > 7) {
        NSString *str1 = [model.tel substringToIndex:3];
        NSString *str2 = [model.tel substringFromIndex:7];
        self.phoneLabel.text = [NSString stringWithFormat:@"%@****%@",str1,str2];
    }else {
        self.phoneLabel.text = model.tel;
    }
    
//    //1000 业主 1001 业主成员 2000 租户 2001租户成员
//    if ([model.houseRelation isEqualToString:@"2000"] || [model.houseRelation isEqualToString:@"2001"]) {
//        self.deleteButton.hidden = NO;
//    }else {
//        self.deleteButton.hidden = YES;
//    }
    
}

@end
